package com.zk.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zk.entity.AllEquipment;
import com.zk.entity.ResultDto;
import com.zk.mapper.AllEquipmentMapper;
import com.zk.service.IAllEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljw
 * @since 2020-11-29
 */

@RestController
@RequestMapping("/zk/all-equipment")
@Api(value = "设备信息管理")
public class AllEquipmentController {
    @Autowired
    private IAllEquipmentService iAllEquipmentService;
    @Resource
    private AllEquipmentMapper allEquipmentMapper;

    /**
     * 增加设备
     */
    @RequestMapping(value = "/",method = RequestMethod.POST)
    @ApiOperation(value="增加设备", notes="test: 仅1和2有正确返回")
    public ResultDto insertAllEquipment(AllEquipment allEquipment){
        //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(allEquipment);
        System.out.println(1111111);
        boolean count = iAllEquipmentService.save(allEquipment);
        return new ResultDto(200,"插入成功",count);
    }
    /**
     * 根据id删除设备
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    @ApiOperation(value="删除设备", notes="test: 仅1和2有正确返回")
    public void deleteAllEquipment(@PathVariable("id") Serializable id){
        System.out.println(id);
        iAllEquipmentService.removeById(id);
    }

    /**
     * 根据id修改设备
     */
    @RequestMapping(value = "/",method = RequestMethod.PUT)
    @ApiOperation(value="根据id修改设备", notes="test: 仅1和2有正确返回")
    public void  updateById(AllEquipment allEquipment){
        iAllEquipmentService.updateById(allEquipment);
    }
    /**
     * 根据id查询
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ApiOperation(value="查询id设备信息", notes="test: 仅1和2有正确返回")
    public AllEquipment  selectById(@RequestParam("id") int id){
        QueryWrapper<AllEquipment> allEquipmentQueryWrapper = new QueryWrapper<>();
        allEquipmentQueryWrapper.eq("equip_id",id);
        AllEquipment allEquipment = iAllEquipmentService.getOne(allEquipmentQueryWrapper);
        return  allEquipment;
    }

    /**
     * 查询所有
     */

    @RequestMapping(value = "/",method = RequestMethod.GET)
    @ApiOperation(value="查询所有设备信息", notes="test: 仅1和2有正确返回")
    public List<AllEquipment> listall(){
        List<AllEquipment> allEquipment = iAllEquipmentService.list(new QueryWrapper<>());
        return allEquipment;
    }

    /**
     * 分页查询
     */
    @RequestMapping(value = "/page",method = RequestMethod.GET)
    @ApiOperation(value="分页查询所有设备信息", notes="test: 仅1和2有正确返回")
    public IPage<Map<String, Object>> pageInfo(){
        IPage<Map<String, Object>> page2=new Page<Map<String, Object>>(1,2);
        return allEquipmentMapper.selectMapsPage(page2 ,null);

    }

}

